package edu.pinkhub.shiro_test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.pinkhub.shiro_test.entity.Menus;
import edu.pinkhub.shiro_test.mapper.MenusMapper;
import edu.pinkhub.shiro_test.service.MenusService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("menusService")
public class MenusServiceImpl extends ServiceImpl<MenusMapper, Menus> implements MenusService {

    @Override
    public List<Menus> findParenMenu(Integer parentid) {
        //查询所有的父菜单
        QueryWrapper<Menus> wrapper=new QueryWrapper<>();
        wrapper.eq("parentid",parentid);
        List<Menus> list=this.list(wrapper);

        for (Menus menus : list) {
            Integer id = menus.getId();
            //根据id查询子菜单
            QueryWrapper<Menus> wrapperid=new QueryWrapper<>();
            wrapperid.eq("parentid",id);
            List<Menus>menusList=this.list(wrapperid);
            //将子菜单填充到父菜单
            menus.setChildren(menusList);
        }
        return list;
    }
}